package servlet;




import service.PhoneService;
import service.impl.PhoneServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * 查找所有手机的Servlet
 */
@WebServlet("/findAllPhones.do")
public class FindAllPhonesServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //调用PhoneService对象
        PhoneService phoneService = new PhoneServiceImpl();
        try {
            //执行查询，把集合存到request中
            req.setAttribute("phones", phoneService.findAllPhones());
            //跳转到宠物列表页面
            req.getRequestDispatcher("/phones.jsp").forward(req,resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
